import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Regular expression test.
 * @author Yong Shin
 *
 */
public class RegexTest {
	public static void main(String args[]) {
		
		String[] TEST_STRS = { 
				"2",
				"2+",
				"2-",
				"1-2",
				"(-2)-",
				"(-2)+",
				"(-2)-(-1)",
				"(-2)-0",
		};
		
		String[] PATTERNS = {
				"(\\d+)\\z",
				"(\\d+)\\+\\z",
				"(\\d+)\\-\\z",
				"\\((\\-\\d+)\\)\\+\\z",
				"\\((\\-\\d+)\\)\\-\\z",
				"(\\d+)\\-(\\d+)\\z",
				"\\((\\-\\d+)\\)\\-(\\d+)\\z",
				"\\((\\-\\d+)\\)\\-\\((\\-\\d+)\\)\\z",
		};
		
		for (int i=0; i<TEST_STRS.length; i++) {
			for (int j=0; j<PATTERNS.length; j++) {
				System.out.println("\"" + TEST_STRS[i] + "\"" + ".matches(\"" + PATTERNS[j] + "\")=" + 
						TEST_STRS[i].matches(PATTERNS[j]));
				Pattern p = Pattern.compile(PATTERNS[j]);
				Matcher m = p.matcher(TEST_STRS[i]);
				if (m.matches()) {
					System.out.print(m.groupCount() + ":");
					for (int k=0; k<=m.groupCount(); k++) {
						System.out.print(m.group(k) + " ");
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}
